<?php

namespace App\Http\Controllers;

use App\Service\BookService;
use Illuminate\Http\Request;

use App\Http\Requests;

class BookManagerController extends Controller
{
    private $bookService;

    public function __construct()
    {
        $this->bookService = new BookService();
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $data = array(
            'BookInfo' => $this->bookService->getAllBook($request->input('bookname')),
        );
        return view('bookmanager',$data);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //添加图书
        return $this->bookService->addBook($request->input());
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Request $request, $id)
    {
        switch ($id) {
            case 'book':
                /**
                 * bookid   书号
                 * bookname 书名
                 * author   作者
                 * press    出版社
                 */
//                print_r($request->input());die;
                return $this->bookService->editBook($request->input());
            default:
                break;
        }
        return null;
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Request $request, $id)
    {
        //删除图书
        return $this->bookService->getBookById($request->input('userid'));
    }
}
